/* 
 * MComboBoxListCellRender.java
 * 本类重写不可编辑组合框的渲染器 
 */
package org.vacoor.ui.qq.combobox;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JList;
/* 
 * @author Vacoor
 */

public class QQComboBoxListCellRender extends DefaultListCellRenderer {
	private static final long serialVersionUID = 1L;
	private QQComboBox MComboBox;
    private Icon icon;

    public QQComboBoxListCellRender(QQComboBox MComboBox) {
        this.MComboBox = MComboBox;
    }

    //覆盖父类返回返回组件方法
    //该方法用于返回已配置用于显示指定值的组件。
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        list.setSelectionBackground(Color.WHITE);
        list.setSelectionForeground(Color.BLACK);
        icon = null==value?null:((QQComItem) value).getIcon();
        if (MComboBox.getFieldIconShow() && icon != null) {
//            icon = ((MComboBoxItem) value).getIcon();
            //调用静态方法MComboBoxPopup.getResizePicture进行缩放
            this.setIcon(QQComboBoxPopup.getResizePicture((ImageIcon) icon, MComboBox.getMinIconDim()));
        }
        this.setText(value == null ? "" : ((QQComItem) value).getNum());

        return this;
    }
    //===============更新输入框图标是否显示=====没有完善
    public void updateIcon(boolean isShow){
        this.setIcon(!isShow?null:QQComboBoxPopup.getResizePicture((ImageIcon) icon, MComboBox.getMinIconDim()));
        this.updateUI();
    }
}